﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace AppUnioeste
{
	[Activity (Label = "Calendario")]			
	public class Calendario : Activity
	{
		private ImageButton left;
		private ImageButton right;
		private TextView diaSemana;
		public static SByte diasEvento = 0;

		//dicionario do exemplo
		Dictionary<string, List<string> > dictGroup = new Dictionary<string, List<string> > ();

		List<string> lstKeys = new List<string> ();

		//lista de dicionarios que representam os dias da semana
		List<Dictionary <string, List<string> >> expandableListData =  new List<Dictionary<string, List<string>>>();

		List<List<string>> dayKeys = new List<List<string>>();

		public String []Days = new String[5]{
			"Segunda-Feira",
			"Terça-feira",
			"Quarta-Feira",
			"Quinta-Feira",
			"Sexta-Feira"
		};

		//adiciona uma expandable list data sem nenhum dado
		public void addExpandableListData(){
			this.expandableListData.Add (new Dictionary<string, List<string>> ());
		}

		//adiciona dados ao dicionario escolhido
		public void AddData(String title, List<String> conteudo, int posicao){
			this.expandableListData.ElementAt (posicao).Add (title, conteudo);
		}


		//seta uma expandable para cada dia
		public void setExpandableListView(Dictionary <string, List<string>> dicionario, List<String> keys){

			var ctlExListBox = FindViewById<ExpandableListView> (Resource.Id.expandableListView1);
			ctlExListBox.SetAdapter (new ExpandableListAdapter (this, dicionario));

			ctlExListBox.ChildClick += delegate(object sender, ExpandableListView.ChildClickEventArgs e) {
				var itmGroup = keys [e.GroupPosition];
				var itmChild = dicionario [itmGroup] [e.ChildPosition];

				//Toast.MakeText (this, string.Format ("You Click on Group {0} with child {1}", itmGroup, itmChild), 
				//	ToastLength.Long).Show ();
				//arrumar o primeiro argumento do PutExtra
				var second = new Intent(this, typeof(InfoCal));
				second.PutExtra("FirstData", itmChild);
				StartActivity(second);
			};
		}

		protected override void OnCreate (Bundle bundle)
		{

			base.OnCreate (bundle);

			// Create your application here
			SetContentView (Resource.Layout.Calendario1);
			CreateExpendableListData ();

			//Dados teste segunda feira
			List<String> tipos = new List<string> ();
			tipos.Add ("Palestras");
			tipos.Add ("Minicursos");
			List<String> palestrasSegunda = new List<String> ();
			palestrasSegunda.Add ("xLupa");
			palestrasSegunda.Add ("PlatMult");
			palestrasSegunda.Add ("SigDengue");
			palestrasSegunda.Add ("Guarda Mirin");
			List<String> minicursosSegunda = new List<String> ();
			minicursosSegunda.Add ("Criando um restaurante interativo: curso prático de prototipagem da experiência");
			minicursosSegunda.Add ("Acessibilidade e Inclusão Digital");
			minicursosSegunda.Add ("Visualização de Informação: introdução e influências de IHC");
			addExpandableListData ();
			AddData (tipos.ElementAt (0), palestrasSegunda, 0);
			AddData (tipos.ElementAt (1), minicursosSegunda, 0);
			//addListData (this.expandableListData.ElementAt (0), l1, l);
			setExpandableListView (this.expandableListData.ElementAt(0),tipos);
			this.dayKeys.Add (tipos);

			//Dados Terça feira
			List<String> palestrasTerca = new List<string> ();
			palestrasTerca.Add ("BeagleBoard na Sociedade");
			palestrasTerca.Add ("IHC na sociedade");
			palestrasTerca.Add ("Tecnicas de IHC");
			addExpandableListData ();
			AddData (tipos.ElementAt (0), palestrasTerca, 1);
			//AddData (tipos.ElementAt (1), minicursosSegunda, 0);

			//Dados quarta feira
			List<String> palestrasQuarta = new List<string> ();
			palestrasQuarta.Add ("Palestra sobre SI");
			palestrasQuarta.Add ("Empreendedorismo");
			addExpandableListData ();
			AddData (tipos.ElementAt (0), palestrasQuarta, 2);


			//Dados quinta feira
			List<String> palestrasQuinta = new List<string> ();
			palestrasQuinta.Add ("Palestra sobre força de vontade");
			palestrasQuinta.Add ("Empreendedorismo 3");
			addExpandableListData ();
			AddData (tipos.ElementAt (0), palestrasQuarta, 3);
			initButtons (tipos);


		}

		void initButtons(List<String> tipos){
			this.left = FindViewById <ImageButton> (Resource.Id.left);
			this.right = FindViewById <ImageButton> (Resource.Id.right);
			//this.left.SetImageResource (Resource.Drawable.left);
			//this.left.SetMaxHeight (50);
			//this.left.SetMaxWidth (50);
			//this.right.SetImageResource (Resource.Drawable.right);
			//this.right.SetMaxHeight (50);
			//this.right.SetMaxWidth (50);

			this.left.Click += (sender, e) =>{
				this.diaSemana = FindViewById<TextView> (Resource.Id.texto);

				if(--diasEvento<0){
					diasEvento = 4;
				}
				this.diaSemana.Text = Days[diasEvento].ToString();
				setExpandableListView (this.expandableListData.ElementAt(diasEvento),tipos);

			};

			this.right.Click += (sender, e) =>{
				this.diaSemana = FindViewById<TextView> (Resource.Id.texto);
				if(++diasEvento>4){
					diasEvento = 0;
				}
				this.diaSemana.Text = Days[diasEvento].ToString();
				setExpandableListView (this.expandableListData.ElementAt(diasEvento),tipos);

			};
		}


		void CreateExpendableListData ()
		{
			for (int iGroup = 1; iGroup <= 3; iGroup++) {
				var lstChild = new List<string> ();
				for (int iChild = 1; iChild <= 3; iChild++) {
					lstChild.Add (string.Format ("Group {0} Child {1}", iGroup, iChild));
				}
				dictGroup.Add (string.Format ("Group {0}", iGroup), lstChild);
			}

			lstKeys = new List<string> (dictGroup.Keys);
		}


		void CreateTstExpendableList(Dictionary<string, List<string> > dictionary, Dictionary<string, List<ExpandableListView> >dictGroup){

			for (int iGroup = 1; iGroup <= 3; iGroup++) {
				var lstChild = new List<ExpandableListView> ();
				for (int iChild = 1; iChild <= 3; iChild++) {
					var listView = FindViewById<ExpandableListView>(Resource.Id.tstExpandable);
					listView.SetAdapter (new ExpandableListAdapterext (this, dictGroup));
					//lstChild.ElementAt (iChild).SetAdapter (new ExpandableListAdapter (this, dictionary));
					lstChild.Add (listView);
				}
				dictGroup.Add (string.Format ("Group {0}", iGroup), lstChild);
				//dictGroup.Add(lstChild
			}

			lstKeys = new List<string> (dictGroup.Keys);
		}


		void init(Dictionary<string, List<string> > dictionary,List<string>listaChaves){
			for (int iGroup = 1; iGroup <= 3; iGroup++) {
				var lstChild = new List<string> ();
				for (int iChild = 1; iChild <= 3; iChild++) {
					lstChild.Add (string.Format ("Group {0} Child {1}", iGroup, iChild));
				}
				dictionary.Add (string.Format ("Group {0}", iGroup), lstChild);
			}

			listaChaves = new List<string> (dictionary.Keys);
		}



		void CreateInternalExpendableList (Dictionary<string, List<string> > dictionary, List<String> Keys, int sizeGroup, int sizeChild)
		{
			for (int iGroup = 1; iGroup <= sizeGroup; iGroup++) {
				var lstChild = new List<string> ();
				for (int iChild = 1; iChild <= sizeChild; iChild++) {
					//Aqui adiciona a chave
					lstChild.Add (string.Format ("Group {0} Child {1}", iGroup, iChild));
				}
				dictionary.Add (string.Format ("Group {0}", iGroup), lstChild);
			}
			Keys = new List<string> (dictionary.Keys);
		}

		void CreateExpendableListDataButton (Dictionary<string, List<Button> > dictionary,List<string>listaChaves)
		{
			for (int iGroup = 1; iGroup <= 3; iGroup++) {
				var lstChild = new List<Button> ();
				for (int iChild = 1; iChild <= 3; iChild++) {
					var button = FindViewById<Button> (Resource.Id.button1);
					lstChild.Add (button);
				}
				dictionary.Add (string.Format ("Group {0}", iGroup), lstChild);
			}

			listaChaves = new List<string> (dictionary.Keys);
		}


	}
}

